classdef DOV < Processor
  % Class for calculating Dissolved Oxygen Voltage ala SBE Data Procesing
  %
  % Author: David Goldsmith, Wash. State Dept. of Ecology, dgol461@ecy.wa.gov
  % Release date: N/A
  
    properties
      % inherited from Processor
      % inData;
      % castDT;
      % scanRate;
      % ParamID;
      % ParamDesc;
      % SBEprec;
      % EquipID;
        DBdata;
        outData;
    end
    
    methods
        function DOV = DOV(data, conn, varargin) % Constructor
            DOV = DOV@Processor(data);
            DOV.getDBdata(conn, 'DOV');
            if isempty(varargin), DOV.mainFormula();
            else DOV.mainFormula(varargin); end
        end
        
        function delete(obj) % Destructor
            % Here in case I need it
        end
        
        function mainFormula(obj, varargin)
            dOV = obj.inData.rV(:,obj.inData.Sensors.OxygenSensor.index-2);            
            tmp = obj.inData.Sensors.OxygenSensor;
            if isfield(tmp, 'ApplyHys') && tmp.ApplyHys ... % i.e., if tmp.ApplyHys is non-zero
                    && ~isempty(varargin) % and non-empty varargin = P was passed in
% TODO: something's wrong, need to figure out what
%                 P = varargin{1}{:};
%                 Voffset = tmp.offset;
%                 hysC = exp(-1/obj.scanRate/tmp.H3);
%                 hysD = 1 + tmp.H1 * (exp(P / tmp.H2) - 1);
%                 V = dOV + Voffset; Vnew = V;
%                 for i=2:length(V)
%                     Vnew(i) = ((V(i) + hysC*hysD(i)*Vnew(i-1)) - hysC*V(i-1)) / hysD(i);
%                 end
%                 dOV = Vnew - Voffset;
            end
            obj.outData = dOV;
        end
        
    end
    
end